#include "customizeedit.h"
#include <QDebug>

CustomizeEdit::CustomizeEdit(QWidget *parent)
    :QLineEdit(parent)
    ,_maxlen(15)
{
    connect(this,&QLineEdit::textChanged,this,&CustomizeEdit::limitMaxLength);
}

void CustomizeEdit::setMaxLength(int maxlen)
{
    _maxlen = maxlen;
}

void CustomizeEdit::focusOutEvent(QFocusEvent *event)
{
    QLineEdit::focusOutEvent(event);
    emit sig_foucus_out();
}

void CustomizeEdit::limitMaxLength(QString text)
{
    if(_maxlen < 0){
        return;
    }
    QByteArray array = text.toUtf8();
    if(array.length()>_maxlen){
        array = array.left(_maxlen);
        setText(QString::fromUtf8(array));
    }
}
